package com.digital.smartgrow.controller.datacenter;

import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.dto.datacenter.ParttimeJobPageDTO;
import com.digital.smartgrow.entity.datacenter.ParttimeJob;
import com.digital.smartgrow.service.datacenter.ParttimeJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 社会兼职情况 前端控制器
 * </p>
 *
 * @author xiewb
 * @since 2022-04-10
 */
@Api(tags = "社会兼职情况")
@RestController
@RequestMapping("${context.prefix}/parttimeJob")
public class ParttimeJobController {

    @Autowired
    private ParttimeJobService parttimeJobService;

    @ApiOperation(value = "列表分页查询")
    @PostMapping("/getListByPage")
    public Object getListByPage(@RequestBody ParttimeJobPageDTO parttimeJobPageDTO){
        return parttimeJobService.getListByPage(parttimeJobPageDTO);
    }

    @ApiOperation(value = "社会兼职情况详情")
    @GetMapping("/getInfo")
    public Object getInfo(Integer id){
        if (id == null) return Result.fail("id不能为空");
        return parttimeJobService.getInfo(id);
    }

    @ApiOperation(value = "社会兼职情况-删除")
    @GetMapping("/removeById")
    public Object removeById(Integer id) {
        if (id == null) return Result.fail("id不能为空");
        return parttimeJobService.removeById(id);
    }

    @ApiOperation(value = "社会兼职情况-新增")
    @PostMapping("/add")
    public Object add(@Valid @RequestBody ParttimeJob parttimeJob) {
        return parttimeJobService.save(parttimeJob);
    }

    @ApiOperation(value = "社会兼职情况-编辑")
    @PostMapping("/edit")
    public Object edit(@Valid @RequestBody ParttimeJob parttimeJob) {
        if (parttimeJob == null || parttimeJob.getId() == null) return Result.fail("id不能为空");
        return parttimeJobService.updateById(parttimeJob);
    }
}
